import java.util.Arrays;

public class Solution66 {
    public int[] plusOne(int[] digits) {
        int t=digits.length-1;
        while (t>=0 && digits[t]==9){
            digits[t]=0;
            t--;
        }
        if (t>=0){
            digits[t]+=1;
            return digits;
        }
        int[] newDigit=new int[digits.length+1];
        Arrays.fill(newDigit,0);
        newDigit[0]=1;
        return newDigit;
    }

    public static void main(String[] args) {
        System.out.println(new Solution66().plusOne(new int[]{9,9,9}).length);
    }
}
